package com.player;

import io.netty.channel.Channel;

import com.alibaba.fastjson.JSONObject;
import com.execaction.AbstractCmdTaskQueue;
import com.execaction.CmdTask;
import com.execaction.CmdTaskQueue;
import com.qy.util.LogUtil;
import com.service.GameServerHandler;


/**
 * 司機用戶
 * 1.保存司機信息
 * 2.保存通道信息
 * 
 * @author zwl
 * 
 */
public abstract class User {

	// netty Channel
	private Channel userChannel;
	
	private CmdTaskQueue cmdTaskQueue;
	
	private int isOnline;
	//我的坐标
	private String myPoint;
	
	public User(CmdTaskQueue cmdTaskQueue) {
		this.cmdTaskQueue = cmdTaskQueue;
	}

	public User() {
		cmdTaskQueue = new AbstractCmdTaskQueue(GameServerHandler.executor);
	}

	public Channel getUserChannel() {
		return userChannel;
	}

	public void setUserChannel(Channel userChannel) {
		this.userChannel = userChannel;
	}

	public void sendPacket(JSONObject json) {
		if (json == null||userChannel==null) {
			LogUtil.error("当前包为空");
			return;
		}
		WorldMgr.sendMsg(userChannel, json);
	}

	public CmdTaskQueue getCmdTaskQueue() {
		return cmdTaskQueue;
	}

	public void enqueue(CmdTask cmdTask) {
		cmdTaskQueue.enqueue(cmdTask);
	}

	public int getIsOnline() {
		return isOnline;
	}

	public void setIsOnline(int isOnline) {
		this.isOnline = isOnline;
	}
	
	public String getMyPoint() {
	    return myPoint;
	}

	public void setMyPoint(String myPoint) {
	    this.myPoint = myPoint;
	}

	/**
	 * 是否在线
	 * @return
	 */
	public boolean isOnline() {
		int status = getIsOnline() ;
		if (status != -1) {
			return status == 1;
		}
		return false;
	}
	//保存信息
	public abstract void save();
	//獲取用戶狀態
	public abstract int getUserStatus();
	//獲取用戶類型
	public abstract int getUserType();
	//獲取用戶id
	public abstract int getID();
	//redis的key
	public abstract String getKey();
	//獲取用戶openid
	public abstract String getOpenId();
}
